package com.finddeer.bookkeeping.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.finddeer.bookkeeping.fragment.TodayFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 消息内容子页面适配器
 */
public class BookkeepingContentFragmentAdapter extends FragmentStatePagerAdapter {
    private List<String> names; //  顶部导航栏

    public BookkeepingContentFragmentAdapter(FragmentManager fm) {
        super(fm);
        this.names = new ArrayList<>();
    }   //  构造函数，初始化names数据列表


    public void setList(List<String> data) {
        this.names.clear();
        this.names.addAll(data);
        notifyDataSetChanged();
    }   //  清空原有的names数据列表，用新的数据替代，并更新顶部导航


    @Override
    public Fragment getItem(int i) {
        return new TodayFragment();
    }

    @Override
    public int getCount() {
        return names.size();
    }   //  返回names数据列表的大小

    @Override
    public CharSequence getPageTitle(int position) {
        String plateName = names.get(position);
        if (plateName == null) {
            plateName = "";
        } else if (plateName.length() > 15) {
            plateName = plateName.substring(0, 15) + "...";
        }
        return plateName;
    }   //  顶部导航栏最多呈现15个字符
}
